/**
 * 
 */
package com.thor.palmmall.rest.workorder.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.palmmall.rest.common.AOperateInfoConverter;
import com.thor.palmmall.rest.common.AWorkOrderConverter;
import com.thor.palmmall.rest.workorder.ABusinessOrder;
import com.thor.palmmall.rest.workorder.ABusinessOrderType;
import com.thor.palmmall.spi.workorder.SBusinessOrder;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class ABusinessOrderConverter implements Converter<SBusinessOrder, ABusinessOrder> {

  public static ABusinessOrderConverter getInstance() {
    if (instance == null)
      instance = new ABusinessOrderConverter();
    return instance;
  }

  private static ABusinessOrderConverter instance;

  private ABusinessOrderConverter() {
  }

  @Override
  public ABusinessOrder convert(SBusinessOrder source) {
    if (source == null) {
      return null;
    }
    ABusinessOrder target = new ABusinessOrder();
    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());
    target.setVersionTime(source.getVersionTime());
    target.setCreateInfo(AOperateInfoConverter.getInstance().convert(source.getCreateInfo()));
    target
        .setLastModifyInfo(AOperateInfoConverter.getInstance().convert(source.getLastModifyInfo()));
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    target.setBillNumber(source.getBillNumber());
    target.setBizState(source.getBizState());
    target.setBpmInstance(source.getBpmInstance());
    target.setBpmMessage(source.getBpmMessage());
    target.setBpmOutgoingState(source.getBpmOutgoingState());
    target.setBpmState(source.getBpmState());
    target.setAbortMsg(source.getAbortMsg());

    target.setWorkOrder(AWorkOrderConverter.getInstance().convert(source.getWorkOrder()));
    if (source.getType() != null) {
      target.setType(ABusinessOrderType.valueOf(source.getType().name()));
    }
    target.setHandler(source.getHandler());
    target.setRemark(source.getRemark());

    return target;
  }
}
